import { type App } from 'vue'
import { EnumFilters, EnumMembers } from '@/common/enum/enum_mediator'
import { ServiceMediator } from '@/common/service/service_mediator'
import { StorageMediator } from '@/common/storage/storage_mediator'
import { ApiMediator } from '@/common/api/api_mediator'
import echarts from '@/common/echarts'
import { type AppConfig } from '@/common/model/app/app_config'
import { defaultLoginInfo } from "@/common/model/app/login_info";

/**
 * 获取应用配置
 * */
async function getAppConfig():Promise<AppConfig> {
    let config:AppConfig;

    try {
        const response = await fetch('/config.json')
        config = await response.json()
    }
    catch (error) {
        console.error('加载配置文件失败:', error)
        config = {
            appName: "",
            apiUrl: {
                app: ""
            }
        }
    }

    return config
}

const appConfig = await getAppConfig();

export default {
    install: (app:App) => {

      // 注册获取应用配置方法
      app.config.globalProperties.$appConfig = appConfig

        // 注册枚举
        app.config.globalProperties.$enumFilters = new EnumFilters()
        app.config.globalProperties.$enumMembers = new EnumMembers()

        // 注册服务
        app.config.globalProperties.$service = new ServiceMediator()

        // 注册存储器
        app.config.globalProperties.$storage = new StorageMediator()

        // 注册Api接口
        app.config.globalProperties.$api = new ApiMediator(app.config.globalProperties)

        // 注册Api接口
        app.config.globalProperties.$echarts = echarts
    }
}
